<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>经纬度坐标格式 | Elasticsearch: 权威指南 | Elastic</title>
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
</head>
<body>
<div class="main-container">
    <section id="content">
        
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原文地址: <a href="https://www.elastic.co/guide/cn/elasticsearch/guide/current/lat-lon-formats.html" rel="nofollow">https://www.elastic.co/guide/cn/elasticsearch/guide/current/lat-lon-formats.html</a>, 版权归 www.elastic.co 所有<br/>
                            英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/guide/current/lat-lon-formats.html" rel="nofollow">https://www.elastic.co/guide/en/elasticsearch/guide/current/lat-lon-formats.html</a>
                            </div>
                        <!-- start body -->
                  <div class="page_header">
<b>请注意:</b><br>本书基于 Elasticsearch 2.x 版本，有些内容可能已经过时。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch: 权威指南</a></span>
»
<span class="breadcrumb-link"><a href="geoloc.html">地理位置</a></span>
»
<span class="breadcrumb-link"><a href="geopoints.html">地理坐标点</a></span>
»
<span class="breadcrumb-node">经纬度坐标格式</span>
</div>
<div class="navheader">
<span class="prev">
<a href="geopoints.html">« 地理坐标点</a>
</span>
<span class="next">
<a href="filter-by-geopoint.html">通过地理坐标点过滤 »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="lat-lon-formats"></a>经纬度坐标格式 (Lat/Lon Formats)<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elasticsearch-cn/elasticsearch-definitive-guide/edit/cn/310_Geopoints/20_Geopoints.asciidoc">edit</a>
</h2>
</div></div></div>
<p>如上例，<code class="word">location</code> 字段被声明为 <code class="literal">geo_point</code> 后，我们就可以索引包含了经纬度信息的文档了。经纬度信息的形式可以是字符串、数组或者对象：</p>
<div class="pre_wrapper lang-json pagebreak-before">
<pre class="programlisting prettyprint lang-json pagebreak-before">PUT /attractions/restaurant/1
{
  "name":     "Chipotle Mexican Grill",
  "location": "40.715, -74.011" <a id="CO226-1"></a><i class="conum" data-value="1"></i>
}

PUT /attractions/restaurant/2
{
  "name":     "Pala Pizza",
  "location": { <a id="CO226-2"></a><i class="conum" data-value="2"></i>
    "lat":     40.722,
    "lon":    -73.989
  }
}

PUT /attractions/restaurant/3
{
  "name":     "Mini Munchies Pizza",
  "location": [ -73.983, 40.719 ] <a id="CO226-3"></a><i class="conum" data-value="3"></i>
}</pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO226-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>字符串形式以半角逗号分割，如 <code class="literal">"lat,lon"</code> 。</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO226-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>对象形式显式命名为 <code class="literal">lat</code> 和 <code class="literal">lon</code> 。</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO226-3"><i class="conum" data-value="3"></i></a></p>
</td>
<td align="left" valign="top">
<p>数组形式表示为 <code class="literal">[lon,lat]</code> 。</p>
</td>
</tr>
</table>
</div>
<div class="caution admon">
<div class="icon"></div>
<div class="admon_content">
<p>可能所有人都至少踩过一次这个坑：地理坐标点用字符串形式表示时是纬度在前，经度在后(<code class="literal">"latitude,longitude"</code>)，而数组形式表示时是经度在前，纬度在后(<code class="literal">[longitude,latitude]</code>) — 顺序刚好相反。</p>
<p>其实，在 Elasticesearch 内部，不管字符串形式还是数组形式，都是经度在前，纬度在后。不过早期为了适配 GeoJSON 的格式规范，调整了数组形式的表示方式。</p>
<p>因此，在使用地理位置的路上就出现了这么一个“捕熊器”，专坑那些不了解这个陷阱的使用者。</p>
</div>
</div>
</div>
<div class="navfooter">
<span class="prev">
<a href="geopoints.html">« 地理坐标点</a>
</span>
<span class="next">
<a href="filter-by-geopoint.html">通过地理坐标点过滤 »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>